<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use App\Constants\Business;
use App\DTO\Request\UserQuery;
use App\DTO\Request\UserLogin;
use App\DTO\Request\CookingUserQuery;
use App\DTO\Request\PopupFormData;
use Hyperf\Context\Context;
use Hyperf\DTO\Annotation\Contracts\RequestQuery;
use Hyperf\DTO\Annotation\Contracts\RequestFormData;
use Hyperf\DTO\Annotation\Contracts\Valid;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\ApiDocs\Annotation\Api;
use Hyperf\ApiDocs\Annotation\ApiOperation;
use Hyperf\ApiDocs\Annotation\ApiHeader;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use L1n6yun\HyperfJwt\Annotation\Auth;
use App\Middleware\ApiResponseMiddleware;
use App\Middleware\CheckSignMiddleware;
use App\Service\UserService;
use Hyperf\Di\Annotation\Inject;
use function L1n6yun\HyperfJwt\auth;

#[Controller(prefix: '/')]
#[Api(tags: 'User管理控制器', position: 1)]
#[Middleware(CheckSignMiddleware::class)]
#[Middleware(ApiResponseMiddleware::class)]
#[ApiHeader(name: 'token', required: true, type: 'string', description: '用户登陆token')]
class UserController extends AbstractController
{

    /**
     * 注入UserService
     * @var UserService
     */
    #[Inject]
    protected UserService $userService;

    /**
     * 玩家设备登录接口
     * User: Ken
     * DateTime: 2024/11/28
     * @param UserLogin $query
     * @return array
     */
    #[GetMapping(path: 'user/login')]
    #[ApiOperation(summary: '玩家设备登录接口')]
    public function userLogin(#[RequestQuery] #[Valid] UserLogin $query): array
    {
        return $this->userService->userLogin($query->device_id);
    }

    /**
     * 玩家设备退出登录接口
     * User: Ken
     * DateTime: 2024/11/28
     * @return array
     */
    #[Auth]
    #[GetMapping(path: 'user/logout')]
    #[ApiOperation(summary: '玩家设备退出登录接口')]
    public function userLogout(): array
    {
        return ['result' => $this->userService->userLogout()];
    }

    /**
     * 玩家游戏特征数据接口
     * User: Ken
     * DateTime: 2024/11/28
     * @param UserQuery $query
     * @return array
     */
    #[Auth]
    #[GetMapping(path: 'user/character')]
    #[ApiOperation(summary: '获取玩家游戏特征数据')]
    public function userCharacter(#[RequestQuery] #[Valid] UserQuery $query): array
    {
        return $this->userService->userCharacter($query->data_version);
    }
}
